home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / MenuMadness / Source / C Source / PlayNotes.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-21  |  1019 b   |  65 lines  |  [TEXT/CWIE]

  1. #include     <QuickTimeComponents.h>
  2. #include    "PlayNotes.h"
  3.  
  4.  
  5. NoteAllocator na = nil;
  6. NoteChannel nc = nil;
  7. NoteRequest nr;
  8.  
  9.  
  10. OSErr    SetupPlaying(void)
  11. {
  12.     ComponentResult thisError;
  13.     long t,i;
  14.  
  15.     na = 0;
  16.     nc = 0;
  17.  
  18.     thisError = EnterMovies();
  19.  
  20.     /*
  21.      * Open up the Note Allocator
  22.      */
  23.     na = OpenDefaultComponent('nota',0);
  24.     if(!na)
  25.         goto goHome;
  26.  
  27.     /*
  28.      * Fill out a Note Request using NAStuffToneDescription
  29.      * to help, and allocate a Note Channel
  30.      */
  31.     //nr.info.flags = 0;            /* post qt 2.0 only */
  32.     //nr.info.reserved = 0;        /* post qt 2.0 only */
  33.     nr.polyphony = 2;        /* simultaneous tones */
  34.     nr.typicalPolyphony = 0x00010000;
  35.     thisError = NAStuffToneDescription(na,1,&nr.tone);    /* 1 is Piano */
  36.  
  37.     thisError = NANewNoteChannel(na,&nr,&nc);
  38.     if(thisError || !nc)
  39.         goto goHome;
  40.  
  41.  
  42. goHome:
  43.     return thisError;
  44.  
  45. }
  46.  
  47.  
  48. OSErr    StopPlaying(void)
  49. {
  50.     if(nc)
  51.         NADisposeNoteChannel(na,nc);
  52.     if(na)
  53.         CloseComponent(na);
  54.         
  55.     ExitMovies();
  56.  
  57. }
  58.  
  59. OSErr    PlayANote(short    pitch)
  60. {
  61.     NAPlayNote(na,nc,pitch,80);    /* middle C at velocity 80 */
  62.  
  63. }
  64.  
  65.